function goTo(ctrl,action,params,update){     
    new Ajax.Updater(
    {
        success:update
    },'/'+ctrl+'/'+action,{
        asynchronous:true,
        evalScripts:true,
        parameters:params,
        on404:function(e){
            alert('not found X')
        }
    }
    );
    return false;
}
function goToDef(ctrl){
    return goToDefinicion(ctrl,'');
}
function goToDefinicion(ctrl,params){
    goTo(ctrl,'create',params,'definicion_show');
    goTo(ctrl,'list',params,'definicion_list');
    return false;
}
function goToShow(ctrl,action){
    if(action=='delete'){
        if(!confirm("Desea Continuar ?"))
            return false
    }
    container=((action=='search')?'definicion_list':'definicion_show')

    params=''
    if(action=='save' || action=='delete'){
        params=extractParams()
//        if(ctrl=='usuario' ) {//&& sendMail()){
//            //loading('loader');
//        }
    }else if(action=='search' || action=='estudio' ){
        params="searchField="+document.getElementById('searchField').value
        if(document.getElementById('superId')){
            params+="&superId="+document.getElementById('superId').value
        }if(document.getElementById('superCodigo')){
            params+="&superCodigo="+document.getElementById('superCodigo').value
        }
    }else if(action=='create'){
        if(document.getElementById('superId')){
            params+="&superId="+document.getElementById('superId').value
        }if(document.getElementById('superCodigo')){
            params+="&superCodigo="+document.getElementById('superCodigo').value
        }

    }
    if (ctrl=="registroNotas"){
        container="divRender1"
    }
    goTo(ctrl,action,params,container)
    return false;
}
function sendMail(){
    return false //(document.getElementById('sendMail').checked)
}
function extractParams(){
    var params=''
    
    for(i=0;i<document.definicion.elements.length;i++){        
        if(document.definicion.elements[i].type=='checkbox' && !document.definicion.elements[i].checked){

        }else if(document.definicion.elements[i].type=='select-multiple' && document.definicion.elements[i].options.length>0){
            var ops=''
            for(var j=0;j<document.definicion.elements[i].options.length;j++){
                ops+=document.definicion.elements[i].options[j].value
                if(j<(document.definicion.elements[i].options.length-1)){
                    ops+=','
                }
            }
            params+=document.definicion.elements[i].name+"="+ops+"&"
        }else{
            params+=document.definicion.elements[i].name+"="+document.definicion.elements[i].value+"&"
        }
    }
    return params
}
function clickPag(event){
    event.stop();
    var link = event.element();
    if(link.href == null){
        return;
    }
    new Ajax.Updater(
    {
        success: $('definicion_list')
    },
    link.href,
    {
        evalScripts: true
    });
}
function clickPagWithSuperId(event){
     event.stop();
    var link = event.element();
    if(link.href == null){
        return;
    }
    new Ajax.Updater(
    {
        success: $('definicion_list')
    },
    link.href,
    {
        evalScripts: true,parameters:'superId='+document.getElementById('superId').value
    });
}

function clickPagWithSuperIdAndCodigo(event){
     event.stop();
    var link = event.element();
    if(link.href == null){
        return;
    }
    new Ajax.Updater(
    {
        success: $('definicion_list')
    },
    link.href,
    {
        evalScripts: true,parameters:'superId='+document.getElementById('superId').value+'&superCodigo='+document.getElementById('superCodigo').value
    });
}

function showSls(id,f){
    d=document.getElementById("sls"+id)
    flag=(d.className=='oculto')
    f.className=(flag)?'sinh':'conh'
    if(!flag){
        hs=d.childNodes
        for(var i=0;i<hs.length;i++){
            if(hs[i].className=='sinh'){
                hs[i].className='conh'
            }else if(hs[i].className=='visible'){
                hs[i].className='oculto'
            }
        }
    }
    d.className=(flag)?'visible':'oculto'
}